package com.mall.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * 购物车实体
 *
 * @author Mall Team
 */
@Data
public class Cart {

    private Long id;
    private Long userId;
    private Long productId;
    private Integer quantity;
    private Integer checkstatus;  // 1-选中 0-未选中
    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    // 关联对象
    private Product product;

    /**
     * 选中状态枚举
     */
    public enum CheckStatus {
        UNCHECKED(0, "未选中"),
        CHECKED(1, "选中");

        private final Integer code;
        private final String desc;

        CheckStatus(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

    /**
     * 是否选中
     */
    @JsonIgnore
    public boolean isChecked() {
        return CheckStatus.CHECKED.getCode().equals(this.checkstatus);
    }

    /**
     * 设置选中状态
     */
    @JsonIgnore
    public void setChecked(boolean checked) {
        this.checkstatus = checked ? CheckStatus.CHECKED.getCode() : CheckStatus.UNCHECKED.getCode();
    }
}